﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ParserCore;

namespace TestParser
{
    [TestClass]
    public class ExpressionToStringTest
    {
        [TestMethod]
        public void ConstantToStringTest()
        {
            var cs1 = new Constant("2");
            var str1 = "2";
            var str2 = "0";

            Assert.AreEqual(cs1.ToString(), str1);
            Assert.AreNotEqual(cs1.ToString(), str2);
        }

        [TestMethod]
        public void IdentifierToStringTest()
        {
            var id1 = new Identifier("a");
            var str1 = "a";
            var str2 = "b";

            Assert.AreEqual(id1.ToString(), str1);
            Assert.AreNotEqual(id1.ToString(), str2);
        }
        [TestMethod]
        public void CallToStringTest()
        {
            var cl1 = new Call(
                new Identifier("+"));
            var cl2 = new Call(
                new Identifier("+"),
                new Constant("5")
                );
            var cl3 = new Call(
                new Identifier("+"),
                new Constant("5"),
                new Constant("5")
                );
            var str11 = "+()";
            var str21 = "+(5)";
            var str31 = "+(5,5)";

            Assert.AreEqual(cl1.ToString(), str11);
            Assert.AreEqual(cl2.ToString(), str21);
            Assert.AreEqual(cl3.ToString(), str31);
        }
        [TestMethod]
        public void NDimArrayBuilderToStringTest()
        {
            Expression[][] exp1 = { };
            Expression[][] exp2 = { new Expression[] { } };
            Expression[][] exp3 = { new Expression[] { },
                                       new Expression[] { } };
            Expression[][] exp4 = { new Expression[] {
                                            new Constant("11"),
                                            new Constant("12")}
                                   };
            Expression[][] exp5 = { new Expression[] {
                                            new Constant("11"),
                                            new Constant("12")},
                                   new Expression[] {
                                            new Constant("21"),
                                            new Constant("22")}};

            var ndim1 = new NDimArrayBuilder(exp1);
            var ndim2 = new NDimArrayBuilder(exp2);
            var ndim3 = new NDimArrayBuilder(exp3);
            var ndim4 = new NDimArrayBuilder(exp4);
            var ndim5 = new NDimArrayBuilder(exp5);
            
            var str1 = "[]";
            var str2 = "[]";
            var str3 = "[;]";
            var str4 = "[11,12]";
            var str5 = "[11,12;21,22]";

            Assert.AreEqual(ndim1.ToString(), str1);
            Assert.AreEqual(ndim2.ToString(), str2);
            Assert.AreEqual(ndim3.ToString(), str3);
            Assert.AreEqual(ndim4.ToString(), str4);
            Assert.AreEqual(ndim5.ToString(), str5);
        }

        [TestMethod]
        public void AnonymousFunctionBuilderToStringTest()
        {
            var afb = new AnonymousFunctionBuilder(
                new Identifier[]{
                    new Identifier("a1"),
                    new Identifier("a2"),
                    new Identifier("a3")},
                new Call(
                    new Identifier("b"),
                    new Constant("1"),
                    new Constant("2"),
                    new Constant("3"))
                    );
            var str = "@(a1,a2,a3)b(1,2,3)";

            Assert.AreEqual(afb.ToString(), str);
        }

        [TestMethod]
        public void CellBuilderToStringTest()
        {
            Expression[][] exp1 = { };
            Expression[][] exp2 = { new Expression[] { } };
            Expression[][] exp3 = { new Expression[] { },
                                       new Expression[] { } };
            Expression[][] exp4 = { new Expression[] {
                                            new Constant("11"),
                                            new Constant("12")}
                                   };
            Expression[][] exp5 = { new Expression[] {
                                            new Constant("11"),
                                            new Constant("12")},
                                   new Expression[] {
                                            new Constant("21"),
                                            new Constant("22")}};

            var cell1 = new CellBuilder(exp1);
            var cell2 = new CellBuilder(exp2);
            var cell3 = new CellBuilder(exp3);
            var cell4 = new CellBuilder(exp4);
            var cell5 = new CellBuilder(exp5);

            var str1 = "{}";
            var str2 = "{}";
            var str3 = "{;}";
            var str4 = "{11,12}";
            var str5 = "{11,12;21,22}";

            Assert.AreEqual(cell1.ToString(), str1);
            Assert.AreEqual(cell2.ToString(), str2);
            Assert.AreEqual(cell3.ToString(), str3);
            Assert.AreEqual(cell4.ToString(), str4);
            Assert.AreEqual(cell5.ToString(), str5);
        }

    }
}
